package com.bp.hearthealth.pulse.lnapps.bp_utils

import android.content.Context
import android.os.Build
import android.os.VibrationEffect
import android.os.Vibrator
import com.bp.hearthealth.pulse.lnapps.BpApplication

object VibrationUtils {

    private var isVibrating = false
    private val vibrator: Vibrator =BpApplication.context.getSystemService(Context.VIBRATOR_SERVICE) as Vibrator

    fun vibratePattern(pattern: LongArray, repeat: Int = 0) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            val vibrationEffect = VibrationEffect.createWaveform(pattern, repeat)
            isVibrating = true
            vibrator.vibrate(vibrationEffect)
        } else {
            vibrator.vibrate(pattern, repeat)
            isVibrating = true
        }
    }

    fun stopVibration() {
        if (isVibrating) {
            vibrator.cancel()
            isVibrating = false
        }
    }

    fun isVibrating(): Boolean {
        return isVibrating
    }
}
